<template>
	<view>
		<view class="hade_title">
			【当前商家】可配送至以下地址
		</view>

		<view style="margin-top: 250rpx;" v-if="address_list.length<1">
			<u-empty mode="data" :iconSize='150' :textSize='24' text='请添加收货地址' icon=""></u-empty>
		</view>

		<view class="content" v-for="(item,index) in address_list" :key="item" @tap="select_site(index,item)">
			<view class="content_left">
				<!-- <image v-show="select_index===index" src="@/static/Project_drawing 26.png" mode=""></image> -->
			</view>
			<view class="content_right">
				<view class="content_right_top">
					<view class="content_right_top_1">
						{{item.address}}-{{item.remark}}
					</view>
					<view class="content_right_top_2" @tap.stop="alter(item.id,item)" v-if="show==0">
						<image src="@/static/Project_drawing 21.png" mode=""></image>
					</view>
					<view class="content_right_top_2" @tap.stop="delete_address(item.id)" v-if="show==1">
						<u-icon name="minus-circle-fill" color="#FD494C" size="44"></u-icon>
					</view>
				</view>
				<view class="content_right_bottom">
					<text>{{item.tag}}</text>
					<text>{{item.title}} ({{item.suffix}})</text>
					<text>{{item.mobile}}</text>
				</view>
			</view>
		</view>
		<height :hg='150'></height>
		<view class="button">
			<view class="button_left" @tap="delete_address_show">
				管理
			</view>
			<view class="btn" @tap="routerTo('/pages/order_all/write_site/write_site?state='+0+ '&item='+ JSON
							.stringify(''))">
				新增收货地址
			</view>
		</view>

	</view>
</template>

<script>
	import {
		address_list,
		address_del
	} from "@/api/comm.js"
	export default {
		data() {
			return {
				select_index: '',
				address_list: [],
				show: 0,
				go_back: '',
				mall_content: {} //积分商城内容
			};
		},
		onLoad(obj) {
			if (obj.query) {
				this.go_back = obj.query.goback
				if (obj.query.item) {
					this.mall_content = JSON.parse(obj.query.item)
				}
			} else {
				this.go_back = obj.goback
			}

			this.address_listApi()
		},
		onShow() {
			this.address_listApi()
		},
		methods: {
			select_site(e, item) {
				this.select_index = e
				if (this.go_back == 0) {
					let pages = getCurrentPages(); // 获取当前的页面栈 
					let prevPage = pages[pages.length - 2]; //  获取上一页面
					prevPage.$item = JSON.stringify(item)
					uni.navigateBack({
						delta: 1 //表示回到上一页面
					})
				} else if (this.go_back == 1) {
					// uni.redirectTo({
					// 	url: '/pages/me_all/confirm/confirm?address=' + JSON.stringify(item) + '&item=' + JSON
					// 		.stringify(this.mall_content)
					// })

					let pages = getCurrentPages(); // 获取当前的页面栈
					let prevPage = pages[pages.length - 2]; //  获取上一页面
					prevPage.$item = {
						address: item,
						item: this.mall_content
					}
					uni.navigateBack({
						delta: 1 //表示回到上一页面
					})
				} else {
					uni.switchTab({
						url: '/pages/me/me'
					})
				}


			},
			alter(id, item) {
				uni.navigateTo({
					url: '/pages/order_all/write_site/write_site?state=' + 1 + "&order_id=" + id + "&item=" + JSON
						.stringify(item)
				})
			},
			async address_listApi() {
				let data = await address_list({
					page: 1,
					limit: 10
				})
				if (data.code == 1) {
					this.address_list = data.data.rows

				} else {
					uni.showToast({
						title: data.msg,
						icon: "none"
					})
				}
			},
			delete_address_show() {
				if (this.show) {
					this.show = 0
				} else {
					this.show = 1
				}
			},
			async delete_address(id) {

				let data = await address_del({
					address_id: id
				})
				uni.showToast({
					title: data.msg,
					icon: "none",
				})
				this.address_listApi()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.hade_title {
		height: 87rpx;
		font-size: 24rpx;
		font-weight: 400;
		color: #333333;
		line-height: 87rpx;
		text-indent: 30rpx;
	}

	.button {
		width: 100%;
		height: 137rpx;
		background: #FFFFFF;
		position: fixed;
		bottom: 0;
		display: flex;
		align-items: center;
		padding: 0 20rpx;

		.button_left {
			font-size: 26rpx;
			font-weight: 400;
			color: #333333;
			padding: 0 20rpx;

		}

		.btn {
			width: 593rpx;
			height: 101rpx;
			background: #02B6FD;
			border-radius: 44rpx;
			font-size: 32rpx;
			font-weight: 400;
			color: #FFFFFF;
			line-height: 101rpx;
			text-align: center;

		}
	}



	.content {
		height: 164rpx;
		background: #FFFFFF;
		display: flex;
		align-items: center;
		margin-bottom: 20rpx;

		.content_left {
			width: 40rpx;
			height: 25rpx;
			// padding: 0 25rpx;
		}

		.content_right {
			width: 600rpx;

			.content_right_top {
				display: flex;
				justify-content: space-between;

				.content_right_top_1 {
					font-size: 28rpx;
					font-weight: 500;
					color: #333333;

					-webkit-line-clamp: 2; //设置几行
					display: -webkit-box; //设置为伸缩盒弹性盒子展示
					overflow: hidden; //超出隐藏
					text-overflow: ellipsis; //设置超出部分以省略号展示
					-webkit-box-orient: vertical; //伸缩盒弹性盒子的排列方式
				}

				.content_right_top_2 {
					width: 30rpx;
					height: 30rpx;
					padding: 0 20rpx;
				}
			}

			.content_right_bottom {
				margin-top: 20rpx;

				text:nth-child(1) {
					width: 52rpx;
					border-radius: 5rpx;
					border: 1rpx solid #B4303D;
					font-size: 24rpx;
					font-weight: 400;
					color: #C84655;
					text-align: center;
					display: inline-block;
				}

				text:nth-child(2) {
					font-size: 24rpx;
					font-weight: 400;
					color: #696969;
					padding: 0 10rpx;
				}

				text:nth-child(3) {
					font-size: 24rpx;
					font-weight: 400;
					color: #696969;
					padding: 0 10rpx;
				}
			}

		}
	}
</style>